package com.help.help.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.form.SysLoginForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class zfbController {
    /**
     *   支付宝的扫描登录
     * auth_code
     */
    @RequestMapping("/auth_code")
    public void auth_code(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String  auth_code=request.getParameter("auth_code");
        String gon="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwJG9HZza3U/tPVnkNLco0OjCV9fR1WMSwedHTR3gsQ5AhrjE5Ep61c0JMO1CTCG7cP6Imx5bUvsDy98JFEgh1jFg51mwaUQqda0svroP0I13DOsSQNNRnvofKprr2wHCphYwpem9Y0NDssSy3Jzlt+5005a2NSyyakU8+a7EFBn/yMg3r7/HtdwMCcj3sZBYpFj8UZc3ekTG9x+yQPeUm/nGWGxqd9DySun6U/5EcIlVMW+FIuUM7QZ6jSLl1ypLBIgWFFuYgyFqqrvHxB261nFRck+rdRBKx+mKNdyXwrkwqxrjQTzBK5bHvoEIcexWjtUkmVqCsQMcKq8EBXXLtwIDAQAB";
        String  s="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCzDlYVUrtuGRtc6ZBeAVbc3obINMG7n2+8zM91CojBduweeaFPOOpsAP721pHeUivf29KApQPao1n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fj+H2ECwp12jRD3+t0aldLP3TOtoCIhGBggWo6JC1FaVmlMBzMPg+hCNu1s2CQKBgCuYvFIfdQVvwEca287dFmBq1I844YHTeSJJMS5sjO/3EhmZ0QEVX16xDf5UnN2Rbbg0yqusE+QrVt6uAIrYOfej2NO4wkAgOUn6VO2/LslxIz74TAYZV0SSvf9PMAdYWuktXdBLrSBCuNm+65CLnIIQT1dga9vmfWDyRlBJfqzdAoGBAM80yRl060GKcNQ/8KIVGUi2ODK3wJfw2c7aVmt5oNBKNvB40bOsdBdjEDqMu0xJ/ojRjCsIDp/fYQjwUz4CIPvq7cFtxnpBFA1xCM1sprpHQHh9zHNylxJdciXwD1Uyd6ItFAqwFld10p9mBuAyD15dxs5/LP1QH2GS8ObLd+/j";
            AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", "2017112600190731", s, "json", "gbk", gon, "RSA2");
            AlipaySystemOauthTokenRequest request1 = new AlipaySystemOauthTokenRequest();
            request1.setCode(auth_code);
            request1.setGrantType("authorization_code");
            try {
                AlipaySystemOauthTokenResponse execute = alipayClient.execute(request1);
                System.out.println(execute.getUserId()+"******");
                request.getSession().setAttribute("userId",execute.getUserId());
                request.getServletContext().setAttribute("userId",execute.getUserId());
            } catch (AlipayApiException e) {

            }
        response.sendRedirect("http://192.168.0.107:8880/#/login");
    }

}
